
#include <stdint.h>
#include "Contract.h"
#include "BSP.h"
#include "Driver.h"
#include "Env.h"
#include "KeyboardBacklight.h"


static uint8_t keyboardState;

void KeyBoard_Init(void){
//		KeyBoardBacklight_Init(envData.backlight);
}

int KeyBoard_Scan(uint8_t* val){
	int keyVal;
	int ret = 0;
	
	switch(keyboardState){
	case 0:{
		//无键按下,等待按键按下
		keyVal = BSP_Keyboard_Scan();
		if(keyVal < 0){
			break;
		}
		if(keyVal < 0x0C){
//				KeyBoardBacklight_Pulse(keyVal, 400);
		}
		*val = keyVal;
		keyboardState = 1;
		ret = 1;
	}
	break;
	
	case 1:{
		int keyState = BSP_Keyboard_Check();
		if(!keyState){
			keyboardState = 0;
		}
	}
	break;

	default:{
		keyboardState = 0;
	}
	break;
	
	}

	return ret;
}


